home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / hf^k-6.dms / in.adf / Install.run / GOLDEDDATA / developer / examples / project / main.c next >
Encoding:
C/C++ Source or Header  |  1996-07-10  |  4.0 KB  |  190 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Example: How to read GoldED's project list. DICE:
  4.  
  5.   dcc main.c -// -o ram:project
  6.  
  7.   This is C source code to demonstrate reading of GoldED's project list using
  8.   ARexx. Might be useful if you intend to develop external project management
  9.   tools.
  10.  
  11.   ------------------------------------------------------------------------------
  12. */
  13.  
  14. /// "includes & prototypes"
  15.  
  16. #include <amiga20/exec/exec.h>
  17. #include <amiga20/rexx/errors.h>
  18. #include <amiga20/rexx/rxslib.h>
  19. #include <amiga20/clib/exec_protos.h>
  20. #include <amiga20/clib/rexxsyslib_protos.h>
  21.  
  22. #define Prototype extern
  23.  
  24. Prototype void            main(ULONG, char **);
  25. Prototype struct RexxMsg *SendRexxCommand(UBYTE *, UBYTE *, struct MsgPort *);
  26. Prototype void            FreeRexxCommand (struct RexxMsg *);
  27. Prototype ULONG           WaitForAnswer(struct MsgPort *, UBYTE *);
  28.  
  29. // globals
  30.  
  31. UBYTE Version[] = "$VER: PRJ 1.2 (" __COMMODORE_DATE__ ")";
  32.  
  33. ///
  34. /// "main"
  35.  
  36. void
  37. main(argc, argv)
  38.  
  39. ULONG argc;
  40. char *argv[];
  41. {
  42.     struct MsgPort *replyPort;
  43.  
  44.     UBYTE *host = "GOLDED.1";
  45.  
  46.     if (replyPort = CreateMsgPort()) {
  47.  
  48.         if (SendRexxCommand(host, "LOCK CURRENT RELEASE=4", replyPort)) {
  49.  
  50.             UBYTE result[80];
  51.  
  52.             if (WaitForAnswer(replyPort, result) == RC_OK) {
  53.  
  54.                 if (SendRexxCommand(host, "QUERY PRJLIST", replyPort)) {
  55.  
  56.                     if (WaitForAnswer(replyPort, result) == RC_OK) {
  57.  
  58.                         struct List *list;
  59.                         struct Node *node;
  60.  
  61.                         list = (struct List *)atol(result);
  62.  
  63.                         if (list->lh_Head->ln_Succ) {
  64.  
  65.                             for (node = list->lh_Head; node->ln_Succ; node = node->ln_Succ)
  66.  
  67.                                 puts(node->ln_Name);
  68.                         }
  69.                         else
  70.                             puts("project list is empty");
  71.                     }
  72.                 }
  73.  
  74.                 if (SendRexxCommand(host, "UNLOCK", replyPort))
  75.  
  76.                     WaitForAnswer(replyPort, result);
  77.             }
  78.         }
  79.  
  80.         DeleteMsgPort(replyPort);
  81.     }
  82.  
  83.     exit(0);
  84. }
  85.  
  86. ///
  87. /// "ARexx"
  88.  
  89. /* -------------------------------------- WaitForAnswer -----------------------
  90.  
  91.   Wait for answer on previously sent message. Free message afterwards. Primary
  92.   return code is returned, the result string (if any) written to <result>.
  93.  
  94. */
  95.  
  96. ULONG
  97. WaitForAnswer(port, result)
  98.  
  99. struct MsgPort *port;
  100. UBYTE          *result;
  101. {
  102.     struct RexxMsg *rexxMsg;
  103.     ULONG  error;
  104.  
  105.     *result = NULL;
  106.  
  107.     do {
  108.         
  109.         WaitPort(port);
  110.  
  111.         if (rexxMsg = (struct RexxMsg *)GetMsg(port)) {
  112.  
  113.             if ((error = rexxMsg->rm_Result1) == RC_OK) {
  114.  
  115.                 if (rexxMsg->rm_Result2)
  116.  
  117.                     strcpy(result, (UBYTE *)rexxMsg->rm_Result2);
  118.             }
  119.         }
  120.  
  121.     } while (!rexxMsg);
  122.  
  123.     FreeRexxCommand(rexxMsg);
  124.  
  125.     return(error);
  126. }
  127.  
  128.  
  129. /* ------------------------------------- FreeRexxCommand ----------------------
  130.  
  131.  Free ARexx message
  132.  
  133. */
  134.  
  135. void
  136. FreeRexxCommand(rexxmessage)
  137.  
  138. struct RexxMsg *rexxmessage;
  139. {
  140.     if (rexxmessage->rm_Result1 == RC_OK) 
  141.  
  142.         if (rexxmessage->rm_Result2)
  143.  
  144.             DeleteArgstring((UBYTE *)rexxmessage->rm_Result2);
  145.  
  146.     DeleteArgstring((UBYTE *)ARG0(rexxmessage));
  147.  
  148.     DeleteRexxMsg(rexxmessage);
  149. }
  150.  
  151.  
  152. /* ---------------------------------- SendRexxCommand -------------------------
  153.  
  154.  Send ARexx message
  155.  
  156. */
  157.  
  158. struct RexxMsg *
  159. SendRexxCommand(port, cmd, replyPort)
  160.  
  161. struct MsgPort *replyPort;
  162. UBYTE          *cmd, *port;
  163. {
  164.     struct MsgPort *rexxport;
  165.     struct RexxMsg *rexx_command_message;
  166.  
  167.     rexx_command_message = NULL;
  168.  
  169.     Forbid();
  170.  
  171.     if (rexxport = FindPort(port)) {
  172.  
  173.         if (rexx_command_message = CreateRexxMsg(replyPort, NULL, NULL)) {
  174.  
  175.             if (rexx_command_message->rm_Args[0] = CreateArgstring(cmd, strlen(cmd))) {
  176.  
  177.                 rexx_command_message->rm_Action = RXCOMM | RXFF_RESULT;
  178.  
  179.                 PutMsg(rexxport, &rexx_command_message->rm_Node);
  180.             }
  181.         }
  182.     }
  183.  
  184.     Permit();
  185.  
  186.     return(rexx_command_message);
  187. }
  188.  
  189. ///
  190.